package com.dongxing.concyrrency.chapter6;

import java.util.concurrent.TimeUnit;

/**
 * @author XavierDong
 **/
public class ThreadCloseGraceful2 {

    private static class Wroker extends Thread {

        @Override
        public void run() {

//            while (true) {
//                try {
//                    TimeUnit.SECONDS.sleep(1);
//                    System.out.println("-------");
//                } catch (InterruptedException e) {
//                    break; // return
//                }
//            }
//
//            // do ----------- something

            while (true) {
                System.out.println("-------");
                if (Thread.interrupted()) {
                    break;
                }
            }

        }

    }


    public static void main(String[] args) {
        Wroker wroker = new Wroker();
        wroker.start();
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        wroker.interrupt();
    }

}
